import math
from PySide6.QtCore import Qt
from PySide6.QtGui import QIntValidator, QDoubleValidator
from PySide6.QtWidgets import  QWidget, QHBoxLayout, QVBoxLayout, QGridLayout, QGroupBox
from qfluentwidgets import SingleDirectionScrollArea, SimpleCardWidget, CaptionLabel, LineEdit, PushButton
from core.util import loadini_price, dumpini_price
from core.log import logger
from core.macharacter import skill_shimen_cost_map, skill_xiulian_cost_map, skill_pet_xiulian_exp_map, xiulianguo_exp, cal_skill_bangpai, SKILL_BANGPAI, init_bangpai, init_shimen, cal_skill_shimen, cal_qianyuandan
import setting as c
from gui.common_gui import GUI_CARD


class CharacterInfoCard(SimpleCardWidget):
    """ App information card """

    def __init__(self, parent=None):
        super().__init__(parent)
        
        init_shimen()
        init_bangpai()
        self.father = parent
        self.card = GUI_CARD.CHARACTER
        
        self.items, ok = loadini_price()
        if not ok:
            logger.error("load price ini failed!")
            exit(-1)
            
        self.alert_lb = CaptionLabel()
        self.alert_lb.setText(c.TIPS_CHARACTER_ALERT)
        
        validator = QIntValidator(0, 999)
        self.shimen_group = QGroupBox(f"师门技能")
        self.shimen_le = []
        self.shimen1_le = LineEdit()
        self.shimen1_le.setPlaceholderText("师门技能1")
        self.shimen1_le.setValidator(validator)
        self.shimen_le.append(self.shimen1_le)
        
        self.shimen2_le = LineEdit()
        self.shimen2_le.setPlaceholderText("师门技能2")
        self.shimen2_le.setValidator(validator)
        self.shimen_le.append(self.shimen2_le)
        
        self.shimen3_le = LineEdit()
        self.shimen3_le.setPlaceholderText("师门技能3")
        self.shimen3_le.setValidator(validator)
        self.shimen_le.append(self.shimen3_le)
        
        self.shimen4_le = LineEdit()
        self.shimen4_le.setPlaceholderText("师门技能4")
        self.shimen4_le.setValidator(validator)
        self.shimen_le.append(self.shimen4_le)
        
        self.shimen5_le = LineEdit()
        self.shimen5_le.setPlaceholderText("师门技能5")
        self.shimen5_le.setValidator(validator)
        self.shimen_le.append(self.shimen5_le)
        
        self.shimen6_le = LineEdit()
        self.shimen6_le.setPlaceholderText("师门技能6")
        self.shimen6_le.setValidator(validator)
        self.shimen_le.append(self.shimen6_le)
        
        self.shimen7_le = LineEdit()
        self.shimen7_le.setPlaceholderText("师门技能7")
        self.shimen7_le.setValidator(validator)
        self.shimen_le.append(self.shimen7_le)
        
        validator = QIntValidator(0, 9)
        self.qianyuandan_le = LineEdit()
        self.qianyuandan_le.setPlaceholderText("乾元丹")
        self.qianyuandan_le.setValidator(validator)
        self.shimen_le.append(self.qianyuandan_le)
        
        self.shimen_cost_lb = CaptionLabel()
        
        validator = QIntValidator(0, 99)
        self.xiulian_group = QGroupBox(f"修炼技能")
        self.xiulian_le = []
        self.gj_xiulian_le = LineEdit()
        self.gj_xiulian_le.setPlaceholderText("攻击修炼")
        self.gj_xiulian_le.setValidator(validator)
        self.xiulian_le.append(self.gj_xiulian_le)
    
        self.fy_xiulian_le = LineEdit()
        self.fy_xiulian_le.setPlaceholderText("防御修炼")
        self.fy_xiulian_le.setValidator(validator)
        self.xiulian_le.append(self.fy_xiulian_le)
        
        self.fs_xiulian_le = LineEdit()
        self.fs_xiulian_le.setPlaceholderText("法术修炼")
        self.fs_xiulian_le.setValidator(validator)
        self.xiulian_le.append(self.fs_xiulian_le)
        
        self.kf_xiulian_le = LineEdit()
        self.kf_xiulian_le.setPlaceholderText("抗法修炼")
        self.kf_xiulian_le.setValidator(validator)
        self.xiulian_le.append(self.kf_xiulian_le)
        
        self.ls_xiulian_le = LineEdit()
        self.ls_xiulian_le.setPlaceholderText("猎术修炼")
        self.ls_xiulian_le.setValidator(validator)
        self.xiulian_le.append(self.ls_xiulian_le)
        
        self.gj_xiulian_limit_le = LineEdit()
        self.gj_xiulian_limit_le.setPlaceholderText("攻修上限")
        self.gj_xiulian_limit_le.setValidator(validator)
        self.gj_xiulian_limit_le.setText("20")
        self.xiulian_le.append(self.gj_xiulian_limit_le)
        
        self.fy_xiulian_limit_le = LineEdit()
        self.fy_xiulian_limit_le.setPlaceholderText("防修上限")
        self.fy_xiulian_limit_le.setValidator(validator)
        self.fy_xiulian_limit_le.setText("20")
        self.xiulian_le.append(self.fy_xiulian_limit_le)
        
        self.fs_xiulian_limit_le = LineEdit()
        self.fs_xiulian_limit_le.setPlaceholderText("法修上限")
        self.fs_xiulian_limit_le.setValidator(validator)
        self.fs_xiulian_limit_le.setText("20")
        self.xiulian_le.append(self.fs_xiulian_limit_le)
        
        self.kf_xiulian_limit_le = LineEdit()
        self.kf_xiulian_limit_le.setPlaceholderText("抗法上限")
        self.kf_xiulian_limit_le.setValidator(validator)
        self.kf_xiulian_limit_le.setText("20")
        self.xiulian_le.append(self.kf_xiulian_limit_le)
        
        self.xiulian_cost_lb = CaptionLabel()
        
        self.pet_xiulian_group = QGroupBox(f"宠物修炼")
        self.pet_xiulian_le = []
        self.gj_pet_xiulian_le = LineEdit()
        self.gj_pet_xiulian_le.setPlaceholderText("攻击控制力")
        self.gj_pet_xiulian_le.setValidator(validator)
        self.pet_xiulian_le.append(self.gj_pet_xiulian_le)
        
        self.fy_pet_xiulian_le = LineEdit()
        self.fy_pet_xiulian_le.setPlaceholderText("防御控制力")
        self.fy_pet_xiulian_le.setValidator(validator)
        self.pet_xiulian_le.append(self.fy_pet_xiulian_le)
        
        self.fs_pet_xiulian_le = LineEdit()
        self.fs_pet_xiulian_le.setPlaceholderText("法术控制力")
        self.fs_pet_xiulian_le.setValidator(validator)
        self.pet_xiulian_le.append(self.fs_pet_xiulian_le)
        
        self.kf_pet_xiulian_le = LineEdit()
        self.kf_pet_xiulian_le.setPlaceholderText("抗法控制力")
        self.kf_pet_xiulian_le.setValidator(validator)
        self.pet_xiulian_le.append(self.kf_pet_xiulian_le)
        
        validator = QIntValidator(0, 99999999)
        self.xlg_le = LineEdit()
        self.xlg_le.setPlaceholderText("修炼果价格")
        self.xlg_le.setText(self.items['xlg'])
        self.xlg_le.setValidator(validator)
        
        self.pet_xiulian_cost_lb = CaptionLabel()
        
        validator = QIntValidator(0, 999)
        self.bangpai_group = QGroupBox(f"帮派技能")
        self.bangpai_le = []
        self.qs_bangpai_le = LineEdit()
        self.qs_bangpai_le.setPlaceholderText("强身术")
        self.qs_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.qs_bangpai_le)
        
        self.mx_bangpai_le = LineEdit()
        self.mx_bangpai_le.setPlaceholderText("冥想")
        self.mx_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.mx_bangpai_le)
        
        self.aq_bangpai_le = LineEdit()
        self.aq_bangpai_le.setPlaceholderText("暗器技巧")
        self.aq_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.aq_bangpai_le)
        
        self.zy_bangpai_le = LineEdit()
        self.zy_bangpai_le.setPlaceholderText("中药医理")
        self.zy_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.zy_bangpai_le)
        
        self.zb_bangpai_le = LineEdit()
        self.zb_bangpai_le.setPlaceholderText("追捕技巧")
        self.zb_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.zb_bangpai_le)
        
        self.tl_bangpai_le = LineEdit()
        self.tl_bangpai_le.setPlaceholderText("逃离技巧")
        self.tl_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.tl_bangpai_le)
        
        self.ys_bangpai_le = LineEdit()
        self.ys_bangpai_le.setPlaceholderText("养生之道")
        self.ys_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.ys_bangpai_le)
        
        self.js_bangpai_le = LineEdit()
        self.js_bangpai_le.setPlaceholderText("健身术")
        self.js_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.js_bangpai_le)
        
        self.qj_bangpai_le = LineEdit()
        self.qj_bangpai_le.setPlaceholderText("巧匠之术")
        self.qj_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.qj_bangpai_le)
        
        self.rl_bangpai_le = LineEdit()
        self.rl_bangpai_le.setPlaceholderText("熔炼技巧")
        self.rl_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.rl_bangpai_le)
        
        self.ls_bangpai_le = LineEdit()
        self.ls_bangpai_le.setPlaceholderText("灵石技巧")
        self.ls_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.ls_bangpai_le)
        
        self.qz_bangpai_le = LineEdit()
        self.qz_bangpai_le.setPlaceholderText("强壮")
        self.qz_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.qz_bangpai_le)
        
        self.ss_bangpai_le = LineEdit()
        self.ss_bangpai_le.setPlaceholderText("神速")
        self.ss_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.ss_bangpai_le)
        
        self.dz_bangpai_le = LineEdit()
        self.dz_bangpai_le.setPlaceholderText("打造技巧")
        self.dz_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.dz_bangpai_le)
        
        self.cf_bangpai_le = LineEdit()
        self.cf_bangpai_le.setPlaceholderText("裁缝技巧")
        self.cf_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.cf_bangpai_le)
        
        self.lj_bangpai_le = LineEdit()
        self.lj_bangpai_le.setPlaceholderText("炼金术")
        self.lj_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.lj_bangpai_le)
        
        self.pr_bangpai_le = LineEdit()
        self.pr_bangpai_le.setPlaceholderText("烹饪技巧")
        self.pr_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.pr_bangpai_le)
        
        self.cl_bangpai_le = LineEdit()
        self.cl_bangpai_le.setPlaceholderText("淬灵之术")
        self.cl_bangpai_le.setValidator(validator)
        self.bangpai_le.append(self.cl_bangpai_le)
        self.bangpai_cost_lb = CaptionLabel()
        
        validator = QDoubleValidator(0.0, 999999.99, 2)
        self.ratio_group = QGroupBox(f"参考价格")
        self.mhb3kw_le = LineEdit()
        self.mhb3kw_le.setPlaceholderText("3000万mhb价值")
        self.mhb3kw_le.setText(self.items['mhb3kw'])
        self.mhb3kw_le.setValidator(validator)
        
        self.cbgprice_le = LineEdit()
        self.cbgprice_le.setPlaceholderText("CBG价格")
        self.cbgprice_le.setValidator(validator)
        
        validator = QDoubleValidator(0.0, 1.00, 2)
        self.ratio_min_le = LineEdit()
        self.ratio_min_le.setPlaceholderText("最低系数")
        self.ratio_min_le.setText("0.3")
        self.ratio_min_le.setValidator(validator)
        self.ratio_max_le = LineEdit()
        self.ratio_max_le.setPlaceholderText("最高系数")
        self.ratio_max_le.setText("0.7")
        self.ratio_max_le.setValidator(validator)
        
        self.gridLayout_ratio = QGridLayout()
        
        self.total_cost_lb = CaptionLabel()
        
        self.tips_label = CaptionLabel('')
        
        self.reset_btn = PushButton('重置')
        self.reset_btn.clicked.connect(lambda: self.onclick_reset())
        self.cal_btn = PushButton('计算')
        self.cal_btn.clicked.connect(lambda: self.onclick_cal())
        
        self.mhb2rmb_le = LineEdit()
        self.mhb2rmb_le.setPlaceholderText("直接价格")
        self.mhb2rmb_le.setReadOnly(True)
        self.rmb_min_le = LineEdit()
        self.rmb_min_le.setPlaceholderText("最低价格")
        self.rmb_min_le.setReadOnly(True)
        self.rmb_max_le = LineEdit()
        self.rmb_max_le.setPlaceholderText("最高价格")
        self.rmb_max_le.setReadOnly(True)
        self.cbgratio_le = LineEdit()
        self.cbgratio_le.setPlaceholderText("CBG系数")
        self.cbgratio_le.setReadOnly(True)

        self.vBoxLayout = QVBoxLayout(self)
        self.hBoxLayout_alert = QHBoxLayout()
        self.gridLayout_shimen = QGridLayout()
        self.hBoxLayout_shimen = QHBoxLayout()
        self.vBoxLayout_shimen = QVBoxLayout()
        self.gridLayout_xiulian = QGridLayout()
        self.hBoxLayout_xiulian = QHBoxLayout()
        self.vBoxLayout_xiulian = QVBoxLayout()
        self.gridLayout_pet_xiulian = QGridLayout()
        self.hBoxLayout_pet_xiulian = QHBoxLayout()
        self.vBoxLayout_pet_xiulian = QVBoxLayout()
        self.gridLayout_bangpai = QGridLayout()
        self.hBoxLayout_bangpai = QHBoxLayout()
        self.vBoxLayout_bangpai = QVBoxLayout()
        self.hBoxLayout_cost = QHBoxLayout()
        self.hBoxLayout_cal = QHBoxLayout()
        
        self.initLayout()

    def initLayout(self):
        self.hBoxLayout_alert.setSpacing(10)
        self.hBoxLayout_alert.setContentsMargins(5, 5, 3, 3)
        self.hBoxLayout_alert.addWidget(self.alert_lb, 4)
        
        positions = [(i, j) for i in range(2) for j in range(5)]
        for i in range(len(self.shimen_le)):
            self.gridLayout_shimen.addWidget(self.shimen_le[i], *positions[i])
        
        self.hBoxLayout_shimen.addWidget(self.shimen_cost_lb)
        self.vBoxLayout_shimen.addLayout(self.gridLayout_shimen)
        self.vBoxLayout_shimen.addLayout(self.hBoxLayout_shimen)
        self.shimen_group.setLayout(self.vBoxLayout_shimen)
        
        for i in range(len(self.xiulian_le)):
            self.gridLayout_xiulian.addWidget(self.xiulian_le[i], *positions[i])
            
        self.hBoxLayout_xiulian.addWidget(self.xiulian_cost_lb)
        self.vBoxLayout_xiulian.addLayout(self.gridLayout_xiulian)
        self.vBoxLayout_xiulian.addLayout(self.hBoxLayout_xiulian)
        self.xiulian_group.setLayout(self.vBoxLayout_xiulian)
        
        for i in range(len(self.pet_xiulian_le)):
            self.gridLayout_pet_xiulian.addWidget(self.pet_xiulian_le[i], *positions[i])
        i = len(self.pet_xiulian_le)
        self.gridLayout_pet_xiulian.addWidget(self.xlg_le, *positions[i])
        
        self.hBoxLayout_pet_xiulian.addWidget(self.pet_xiulian_cost_lb)
        self.vBoxLayout_pet_xiulian.addLayout(self.gridLayout_pet_xiulian)
        self.vBoxLayout_pet_xiulian.addLayout(self.hBoxLayout_pet_xiulian)
        self.pet_xiulian_group.setLayout(self.vBoxLayout_pet_xiulian)
        
        positions = [(i, j) for i in range(4) for j in range(5)]
        for i in range(len(self.bangpai_le)):
            self.gridLayout_bangpai.addWidget(self.bangpai_le[i], *positions[i])
        
        self.hBoxLayout_bangpai.addWidget(self.bangpai_cost_lb)
        self.vBoxLayout_bangpai.addLayout(self.gridLayout_bangpai)
        self.vBoxLayout_bangpai.addLayout(self.hBoxLayout_bangpai)
        self.bangpai_group.setLayout(self.vBoxLayout_bangpai)
        
        self.gridLayout_ratio.addWidget(self.mhb3kw_le, 0, 0)
        self.gridLayout_ratio.addWidget(self.ratio_min_le, 0, 1)
        self.gridLayout_ratio.addWidget(self.ratio_max_le, 0, 2)
        self.gridLayout_ratio.addWidget(self.cbgprice_le, 0, 3)
        self.gridLayout_ratio.addWidget(self.mhb2rmb_le, 1, 0)
        self.gridLayout_ratio.addWidget(self.rmb_min_le, 1, 1)
        self.gridLayout_ratio.addWidget(self.rmb_max_le, 1, 2)
        self.gridLayout_ratio.addWidget(self.cbgratio_le, 1, 3)
        
        self.ratio_group.setLayout(self.gridLayout_ratio)
        
        self.hBoxLayout_cal.addWidget(self.reset_btn)
        self.hBoxLayout_cal.addWidget(self.cal_btn)
        self.hBoxLayout_cost.addWidget(self.total_cost_lb)
        self.hBoxLayout_cost.addWidget(self.tips_label)
        
        self.vBoxLayout.addLayout(self.hBoxLayout_alert)
        self.vBoxLayout.addWidget(self.shimen_group)
        self.vBoxLayout.addWidget(self.xiulian_group)
        self.vBoxLayout.addWidget(self.pet_xiulian_group)
        self.vBoxLayout.addWidget(self.bangpai_group)        
        self.vBoxLayout.addLayout(self.hBoxLayout_cal)
        self.vBoxLayout.addLayout(self.hBoxLayout_cost)
        self.vBoxLayout.addWidget(self.ratio_group)
        
    def get_gong_xiu_max_cost(self, level):
        if level == 21:
            return 12870000
        elif level == 22:
            return 27000000
        elif level == 23:
            return 42450000
        elif level == 24:
            return 59280000
        elif level == 25:
            return 77550000
        else:
            return 0
        
    def get_fang_xiu_max_cost(self, level):
        return self.get_gong_xiu_max_cost(level) * 2 / 3
        
        
    def setTips(self, tips):
        self.tips_label.setText(f"<font color='red'>{tips}</font>")
        
    def cal_shimen(self):
        mhb = 0
        exp = 0
        
        for i, le in enumerate(self.shimen_le):
            t = le.text()
            print(f'shimen {t}')
            if t == "" or t == "0":
                continue
            sp = int(t)
            if i < 7: # 师门技能
                res,  ok, = cal_skill_shimen(0, sp)
                mhb += math.floor(res['mhb'])
                exp += math.floor(res['exp'])
            elif i == 7: #乾元丹
                res,  ok, = cal_qianyuandan(0, sp)
                mhb += math.floor(res['mhb'])
                exp += math.floor(res['exp'])
            
        return mhb, exp
    
    def cal_xiulian(self):
        total = 0
        for i, le in enumerate(self.xiulian_le):
            t = le.text()
            if t == "" or t == "0":
                continue
            sp = int(t)
            if i == 0 or i == 2 or i == 4:  # 攻修 法修 猎术
                total += skill_xiulian_cost_map[sp]
            elif i == 1 or i == 3:   # 防修 抗法
                total +=  int(skill_xiulian_cost_map[sp] * 2 / 3)
            elif i == 5 or i == 7: # 攻修上限 法修上限
                total += self.get_gong_xiu_max_cost(sp)
            elif i == 6 or i == 8: # 防修上限 抗法上限
                total += self.get_fang_xiu_max_cost(sp)
        return total
    
    def cal_pet_xiulian(self):
        tt = self.xlg_le.text()
        xlg_price = float(tt)
        exp = 0
        for i, le in enumerate(self.pet_xiulian_le):
            t = le.text()
            if t == "" or t == "0":
                continue
            sp = int(t)
            exp += skill_pet_xiulian_exp_map[sp]
        total = math.ceil(exp / xiulianguo_exp) * xlg_price
        return total
    
    def cal_bangpai(self):
        mhb = 0
        exp = 0
        bg = 0
        for i, le in enumerate(self.bangpai_le):
            t = le.text()
            if t == "" or t == "0":
                continue
            sp = int(t)
            res, ok = cal_skill_bangpai(SKILL_BANGPAI(i), 0, sp)
            mhb += math.floor(res['mhb'])
            exp += res['exp']
            bg += res['bg_use']
        return mhb, exp, bg
    
    def onclick_cal(self):
        self.tips_label.clear()
        self.items['xlg'] = self.xlg_le.text()
        self.items['mhb3kw'] = self.mhb3kw_le.text()
        dumpini_price(self.items)
        try:
            shimen_mhb, shimen_exp = self.cal_shimen()
            self.shimen_cost_lb.setText(f"mhb: <font color=red>{shimen_mhb:,}</font> exp: <font color=green>{shimen_exp:,}</font>")
        except Exception as e:
            logger.error(f"An unexpected error occurred: {str(e)}")
            self.setTips("师门技能非法")
            return

        try:
            xiulian_mhb = self.cal_xiulian()
            self.xiulian_cost_lb.setText(f"mhb: <font color=red>{xiulian_mhb:,}</font>")
        except Exception as e:
            logger.error(f"An unexpected error occurred: {str(e)}")
            self.setTips("修炼技能非法")
            return
            
        try:
            pet_xiulian_mhb = self.cal_pet_xiulian()
            self.pet_xiulian_cost_lb.setText(f"mhb: <font color=red>{pet_xiulian_mhb:,}</font>")
        except Exception as e:
            logger.error(f"An unexpected error occurred: {str(e)}")
            self.setTips("宠物修炼技能非法")
            return
        
        try:
            xibangpai_mhb, bangpai_exp, bangpai_bg = self.cal_bangpai()
            self.bangpai_cost_lb.setText(f"mhb: <font color=red>{xibangpai_mhb:,}</font> exp: <font color=green>{bangpai_exp:,}</font> bg: <font color=black>{bangpai_bg:,}</font>")
        except Exception as e:
            logger.error(f"An unexpected error occurred: {str(e)}")
            self.setTips("帮派技能非法")
            return
            
        mhb_total = math.floor(shimen_mhb + xiulian_mhb + pet_xiulian_mhb + xibangpai_mhb)
        exp_total = shimen_exp + bangpai_exp
        self.total_cost_lb.setText(f"[total] mhb: <font color=red>{mhb_total:,}</font> exp: <font color=green>{exp_total:,}</font> ")
        
        tt = self.mhb3kw_le.text()
        if tt.strip() and mhb_total != 0:  # 检查文本是否为空或只包含空格
            mhb_rato = float(tt) / 30000000
            mhb2rmb = mhb_total * mhb_rato
            self.mhb2rmb_le.setText(f"{mhb2rmb:.2f}")
            
            tt = self.ratio_min_le.text()
            if tt.strip(): 
                min_ratio = float(tt)
                min_price = min_ratio * mhb2rmb
                self.rmb_min_le.setText(f"{min_price:.2f}")
                
            tt = self.ratio_max_le.text()
            if tt.strip(): 
                max_ratio = float(tt)
                max_price = max_ratio * mhb2rmb
                self.rmb_max_le.setText(f"{max_price:.2f}")
                
            tt = self.cbgprice_le.text()
            if tt.strip(): 
                cbgprice = float(tt)
                cbgratio = cbgprice / mhb2rmb
                self.cbgratio_le.setText(f"{cbgratio:.2f}")
        
    
    def onclick_reset(self):
        for le in self.shimen_le:
            le.clear()
        self.shimen_cost_lb.clear()
        
        for le in self.xiulian_le:
            le.clear()
        self.xiulian_cost_lb.clear()
    
        for le in self.pet_xiulian_le:
            le.clear()
        self.pet_xiulian_cost_lb.clear()
            
        for le in self.bangpai_le:
            le.clear()
        self.bangpai_cost_lb.clear()
        
        self.total_cost_lb.clear()
        
        self.gj_xiulian_limit_le.setText("20")
        self.fy_xiulian_limit_le.setText("20")
        self.fs_xiulian_limit_le.setText("20")
        self.kf_xiulian_limit_le.setText("20")
        
        self.cbgprice_le.clear()
        self.mhb2rmb_le.clear()
        self.rmb_min_le.clear()
        self.rmb_max_le.clear()
        self.cbgratio_le.clear()
        
        self.tips_label.clear()
        
        

class CharacterInterface(SingleDirectionScrollArea):
    

    def __init__(self, parent=None):
        super().__init__(parent=None)
        self.main_window = parent
        self.view = QWidget(self)

        self.vBoxLayout = QVBoxLayout(self.view)
        self.characterCard = CharacterInfoCard(self)
        self.characterCard.setMaximumWidth(c.card_width)
        self.setWidget(self.view)
        self.setWidgetResizable(True)
        self.setObjectName('CharacterInterface')

        self.vBoxLayout.setSpacing(10)
        self.vBoxLayout.setContentsMargins(0, 0, 15, 0)
        self.vBoxLayout.addWidget(self.characterCard, 0, Qt.AlignTop)

        self.setStyleSheet("QScrollArea {border: none; background:transparent}")
        self.view.setStyleSheet('QWidget {background:transparent}')
        
    def show(self):
        logger.info("show CharacterInterface")
        